/*----------------------------------------------------------------------------------------
*
*  Copyright 2019, Gao Hai Hui, <fromzeropoint@126.com>.  All rights reserved.
*  https://gitee.com/helloworldghh/xoskit.git
*  Use of this source code is governed by a MIT license
*  that can be found in the License file.
*
----------------------------------------------------------------------------------------*/
#ifndef __XOS_STL_POOL_PROTOCOL_DB_DB_DATA_H__
#define __XOS_STL_POOL_PROTOCOL_DB_DB_DATA_H__

#include "../public/public_field.h"

namespace xos_protocol
{

    template< class T, class PACKER >
	class db_data : public public_field< T, PACKER >
	{
	public:
        //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
        // 
		typedef public_field< T, PACKER > BASE;
	public:
        //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
        // 
		db_data( xos_box::i_serial * pSerial, xos_box::i_buf * pBuf ) : 
			BASE( pSerial, pBuf )
		{
		}
		~db_data()
		{
		}
	public:
        //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
        // 
		int req_compose( int nCookie, int nCmd, T * pT )
		{
			int ret = 0;
            if( 0 == ret )
            {
                ret = BASE::set_fields_by_data( pT );
            }
			if( 0 == ret )
			{
                ret = BASE::req_compose( nCookie, nCmd );
			}
            if( 0 == ret )
            {
                ret = BASE::pack_data( pT );
            }
			return ret;
		}
		int req_dis_compose( T * pT )
		{
			int ret = 0;
            if( 0 == ret )
            {
                ret = BASE::req_dis_compose();
            }
            if( 0 == ret )
            {
                ret = BASE::un_pack_data( pT );
            }
			return ret;
		}
        //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
        // 
		int res_compose( int nCookie, int nCmd, int nRet, T * pT )
		{
			int ret = 0;
            if( 0 == ret )
            {
                ret = BASE::set_fields_by_data( pT );
            }
			if( 0 == ret )
			{
                ret = BASE::res_compose( nCookie, nCmd, nRet );
			}
            if( ( 0 == ret ) && ( 0 == nRet ) )
            {
                ret = BASE::pack_data( pT );
            }
			return ret;
		}
		int res_dis_compose( int & nRet, T * pT )
		{
            int ret = 0;
            if( 0 == ret )
            {
                ret = BASE::res_dis_compose( nRet );
            }
            if( ( 0 == ret ) && ( 0 == nRet ) )
            {
                ret = BASE::un_pack_data( pT );
            }
            return ret;
		}
	};

}

#endif // __XOS_STL_POOL_PROTOCOL_DB_DB_DATA_H__
